
//获取session中的产品和订单id
var orderId = window.sessionStorage.getItem("orderid");
var proId = window.sessionStorage.getItem("proid");

//页面加载时调用全部订单的获取方法
$(function() {
    getOrderDetail();


});

//============================================================================
//                          获取订单详情
//============================================================================
function getOrderDetail(){
    var sendUrl = "/order_detail/" + orderId + "/" + proId;

    $.ajax({
        url : sendUrl,
        type : "GET",
        datatype : "json",
        success : function(data) {
            console.log(data);

            var tras = new Array();
            tras = data.data.travellers;

            var flow = data.data.flow;

            var product = data.data.product;

            var order = data.data.order;
            // console.log(tras[0])

            //开始渲染
            //清空订单详情
            $('.detail_body').empty();
            //jsp 到出行旅客部分
            var addHtml = " <!--\n" +
                "                    订单信息部分\n" +
                "        -->\n" +
                "        <div class=\"detail_model\">\n" +
                "            <div class=\"detail_title\">\n" +
                "                <span>订单信息</span>\n" +
                "            </div>\n" +
                "            <div class=\"detail_info\">\n" +
                "                <ul>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">订单流水号：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">" +flow.flowNum + "</span>\n" +
                "                    </li>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">产品名称：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">" +product.productName + "</span>\n" +
                "                    </li>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">下单时间：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">" +flow.createTime + "</span>\n" +
                "                    </li>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">订单金额：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">￥</span>\n" +
                "                        <span class=\"desc expect_cost\">" +order.orderMoney + "</span>\n" +
                "                    </li>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">实付金额：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">￥</span>\n" +
                "                        <span class=\"desc actual_cost\">" +flow.paidAmount + "</span>\n" +
                "                    </li>\n" +
                "                    <!--\n" +
                "                                    订单状态：\n" +
                "                       当状态为：已结束时  显现评价的按钮\n" +
                "                    -->\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">订单状态：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">" +order.orderStatus + "</span>\n" +
                "                        <a href=\"javascript:void(0);\" class=\"desc evaluation\" onclick='addEvaluation()'>立即评价</a>\n" +
                "                    </li>\n" +
                "                </ul>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "        <!--\n" +
                "                    联系人部分\n" +
                "        -->\n" +
                "        <div class=\"detail_model\">\n" +
                "            <div class=\"detail_title\">\n" +
                "                <span>联系人信息</span>\n" +
                "            </div>\n" +
                "            <div class=\"detail_info\">\n" +
                "                <ul>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">姓名：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">" +tras[0].travellerName +"</span>\n" +
                "                    </li>\n" +
                "                    <li>\n" +
                "                        <span class=\"key\">手机号：&nbsp;&nbsp;</span>\n" +
                "                        <span class=\"desc\">" +tras[0].travellerTelno + "</span>\n" +
                "                    </li>\n" +
                "                </ul>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "        <!--\n" +
                "                    出行人信息部分\n" +
                "        -->\n" +
                "        <div class=\"detail_model\">\n" +
                "            <div class=\"detail_title\">\n" +
                "                <span>出行人信息</span>\n" +
                "            </div>"

            $('.detail_body').append(addHtml);

            $.each(tras,function (i,val) {
                var count = i + 1;
                $('.detail_body').append(
                    "<!--\n" +
                    "                   这是一个单个的出行人信息（测试）\n" +
                    "            -->\n" +
                    "            <div>\n" +
                    "                <div class=\"detail_traveler\">\n" +
                    "                    <p class=\"fare\">\n" +
                    "                        <span>旅客&nbsp;&nbsp;</span>\n" +
                    "                        <span class=\"t_no\">" + count + "</span>\n" +
                    "                    </p>\n" +
                    "                    <p class=\"t_type\">\n" +
                    "                        <span>(</span>\n" +
                    "                        <span>" +tras[i].travellerType + "</span>\n" +
                    "                        <span>)</span>\n" +
                    "                    </p>\n" +
                    "\n" +
                    "                </div>\n" +
                    "                <div class=\"detail_info detail_t_ul\">\n" +
                    "                    <ul>\n" +
                    "                        <li>\n" +
                    "                            <span class=\"key\">姓名：&nbsp;&nbsp;</span>\n" +
                    "                            <span class=\"desc\">" +tras[i].travellerName +"</span>\n" +
                    "                        </li>\n" +
                    "                        <li>\n" +
                    "                            <span class=\"key\">手机号：&nbsp;&nbsp;</span>\n" +
                    "                            <span class=\"desc\">" +tras[i].travellerTelno + "</span>\n" +
                    "                        </li>\n" +
                    "                    </ul>\n" +
                    "                </div>\n" +
                    "                <div class=\"split_line\"></div>\n" +
                    "            </div>"
                )
            })
            $('.detail_body').append(
                "</div>"
            )
        } //success
    })
}


function addEvaluation() {

    $(location).attr('href', '/addEvaluation');

}

//点击名称进入首页
$(".nav_userName").click(function () {

    $.ajax({
        url: "/order/getId",
        type: "GET",
        datatype: "json",
        success: function (data) {
            console.log(data.data)
            window.sessionStorage.setItem("cusid", data.data)
            $(location).attr('href', 'order');
        }

    })

});